package com.example.timyag.service.impl;

import javax.annotation.Resource;

import java.util.List;

import com.example.timyag.service.ITestServiceb;
import com.example.timyag.service.bo.BookBo;
import com.example.timyag.service.impl.entity.Book;
import com.example.timyag.service.impl.mapper.BookMapperb;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author yangjf
 * @time 2019-04-10 17:16
 */
@Service
public class TestServiceImplb implements ITestServiceb {

    @Resource(name = "bookMapperb")
    private BookMapperb bookMapperb;

    @Autowired
    private TestComponentb testComponentb;

    @Override
    public String sayHello(String p1) {
        testComponentb.test();
        return "hello, " + p1 + ":this is service Impl2 ";
    }

    @Override
    public BookBo addBook(String name) {
        Integer id = bookMapperb.selectMaxId();
        System.out.println(id);
        Book book = new Book();
        book.setId(id + 1);
        book.setName(name);
        List<Book> books = bookMapperb.selectList();
        for (int i = 0; i < 2; i++) {
            System.out.println("testServiceImpl b: " + books.get(i));
        }
        bookMapperb.insert(book);
        Book dbBook = bookMapperb.selectById(book.getId());
        System.out.println("数据库根据主键id查询结果：" + dbBook.getName());
        return new BookBo(book.getId(), book.getName());
    }
}
